package com.leadingsoft.pwxk.controller;

import java.io.IOException;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import com.leadingsoft.pwxk.service.RiverBasinRegionService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;

/**
 * 
 * @author ysh
 * @desc 流域与区划关系
 */
@Api(description = "流域与区划关系")
@RestController
@RequestMapping("api/riverBasinRegion")
@Slf4j
public class RiverBasinRegionController {

	@Autowired
	RiverBasinRegionService riverBasinRegionService;

	@ApiOperation("导入")
	@PostMapping("upload")
	@ResponseStatus(code = HttpStatus.OK)
	public void upload(MultipartHttpServletRequest request, @RequestParam String type) {
		try {
			riverBasinRegionService.importData(request, type);
		} catch (IOException e) {
			log.error("流域与区划关系上传失败" + e.getMessage(), e);
		}
	}

	@ApiOperation("流域列表")
	@GetMapping
	@ResponseStatus(code = HttpStatus.OK)
	public List<String> getList() {
		return riverBasinRegionService.getList();
	}
}
